<?php
namespace froyo\cherry\Logger;
use froyo\cherry\Base\BaseLogger;
class FileLogger extends BaseLogger{
	public $logpath = CHERRY_APP_ROOT.'/runtime/log';
	public $maxfilesize = 8400000;//8m

	protected function getlogfilepath($type){
		$dir = $this->logpath.'/'.date('Ym');
		if(!is_dir($dir ))
		{
			mkdir($dir,0777,true);
		}
		$file = $dir .'/'.date('d');
		if(in_array($type, $this->stands))
		{
			$file .='_'.$type;
		}
		$file .='.log';

		if(file_exists($file))
		{
			if( filesize($file) > $this->maxfilesize)
			{
				$newname = substr($file, 0,strrpos($file, '.')).'_'.time().'.log';
				@rename($file,$newname);
			}
		}
		return $file;
		
	}
	function writelog($type,$msg){
		$path = $this->getlogfilepath($type);
		file_put_contents($path, $type.'|'.time().'|'.$msg."\n",FILE_APPEND);
	}
}